using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace Unitins.Component.Repository.Sepsi
{
    public class PacienteManager : Unitins.Component.ComponentMaster.ManagerMaster<Paciente, PacienteCollection>
    {
        [DataObjectMethod(DataObjectMethodType.Select)]
        public static Paciente Buscar(Int64 idPaciente)
        {
            return Buscar(idPaciente, PacienteAttribute.IdPaciente);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public static PacienteCollection Filtro(string valor, int campoFiltro, int campoOrdenacao, string tipoOrdenacao)
        {
            PersistenceLayer.DataBase.Parameter.PLSearchMounter<Paciente> myMounter = new Unitins.Component.PersistenceLayer.DataBase.Parameter.PLSearchMounter<Paciente>();

            Unitins.Component.PersistenceLayer.DataBase.Parameter.PLSearchMounterSortType mySortType = Unitins.Component.PersistenceLayer.DataBase.Parameter.PLSearchMounterSortType.Ascending;

            if(tipoOrdenacao.ToLower().Equals("desc"))
                mySortType = Unitins.Component.PersistenceLayer.DataBase.Parameter.PLSearchMounterSortType.Descending;

            myMounter.Parameters.Add(new Unitins.Component.PersistenceLayer.DataBase.Parameter.PLSearchMounterParameter((PacienteAttribute)campoFiltro, valor, Unitins.Component.PersistenceLayer.DataBase.Parameter.PLSearchMounterCompareType.Like, Unitins.Component.PersistenceLayer.DataBase.Parameter.PLSearchMounterConditionType.And));
            myMounter.SortCollection.Add(new Unitins.Component.PersistenceLayer.DataBase.Parameter.PLSearchMounterSort((PacienteAttribute)campoOrdenacao, mySortType));

            return PersistenceLayer.Manager.SearchAll<Paciente, PacienteCollection>(myMounter);
        }
    }
}
